package com.flank.weather.ui.place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.flank.weather.logic.Repository
import com.flank.weather.logic.dao.PlaceDao
import com.flank.weather.logic.model.PlaceResponse

/**
 * Created by 2021/9/1
 * Email 270554501@qq.com
 * Author Flank
 *
 */
class PlaceViewModel : ViewModel() {

    private val searchLiveData = MutableLiveData<String>()
    val placeList = ArrayList<PlaceResponse.Place>()
    val placeLiveData = Transformations.switchMap(searchLiveData) { query ->
        Repository.searchPlaces(query)
    }

    fun searchPlaces(query: String) {
        searchLiveData.value = query
    }
    fun savePlace(place: PlaceResponse.Place) = Repository.savePlace(place)
    fun getSavePlace()= Repository.getSavePlace()
    fun isPlaceSaved()= Repository.isPlaceSaved()
}